﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using ZYLeGo2._0.Models;

namespace ZYLeGo2._0.Controllers
{
    public class WelcomeController : Controller
    {
        // GET: Welcome
        public ActionResult Login()
        {
            return View();
        }
        //登录验证
        [HttpPost]
        public ActionResult Login(User user)
        {
            using (TradeDBEntities1 db=new TradeDBEntities1())
            {
                var u = db.Users.FirstOrDefault(x => x.UsersAccount == user.UsersAccount && x.UsersPassword == user.UsersPassword);
                if (u == null)
                {
                    ModelState.AddModelError("", "账号或密码错误！！！");
                   
                }
                else
                {
                    return RedirectToAction("Index","Home");   //登陆成功
                }
                
            }
            return View();
        }


        public ActionResult Register()
        {
            return View();
        }
        //注册验证
        [HttpPost]
        public ActionResult Register(User user)
        {
            using (TradeDBEntities1 db = new TradeDBEntities1())
            {
                var u = db.Users.FirstOrDefault(x => x.UsersAccount == user.UsersAccount && x.UsersPassword == user.UsersPassword);
                if (u == null)
                {
                    ModelState.AddModelError("", "账号或密码错误！！！");
                }
                else
                {
                    return RedirectToAction("Index", "Home");   //登陆成功
                }
            }
            return View();
        }
    }
}